import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

export const API = {
  // 工单列表分页
  page: '/order/page',
  // 工单列表
  list: '/order/list',
  // 工单删除
  delete: '/order/delete',
  // 工单详情
  info: '/order/info',
  // 新增工单信息
  add: '/order/add',
  // 修改工单信息
  modify: '/order/modify',
  // 更新PIC图
  updateGraph: '/order/update-graph',
  // 确认访问
  confirm: '/order/confirm',
  // 分派
  assgin: '/order/assgin',
  // 转派
  resign: '/order/resign',
  // 处理
  handle: '/order/handle',
  // 结单
  audit: '/order/audit',
  // 维修人员回退
  signback: '/order/signback',
  // 维修人员维修处理
  repair: '/order/repair',
  // 厂长退回
  redo: '/order/redo'
};
/**
 * 转派
 */
export const resignOrderApi = async (params) => {
  return await defHttp.post({ url: API.resign, params });
};

/**
 * 分派
 */
export const assginOrderApi = async (params) => {
  return await defHttp.post({ url: API.assgin, params });
};

/**
 * 厂长回退
 */
export const redoOrderApi = async (params) => {
  return await defHttp.post({ url: API.redo, params });
};

/**
 * 处理
 */
export const handleOrderApi = async (params) => {
  return await defHttp.post({ url: API.handle, params });
};

/**
 * 结单
 */
export const auditOrderApi = async (params) => {
  return await defHttp.post({ url: API.audit, params });
};

/**
 * 回退
 */
export const signbackOrderApi = async (params) => {
  return await defHttp.post({ url: API.signback, params });
};

/**
 * 维修处理
 */
export const repairOrderApi = async (params) => {
  return await defHttp.post({ url: API.repair, params });
};


/**
 * 确认访问
 */
export const confirmVistitApi = async (params) => {
  return await defHttp.post({ url: API.confirm, params });
};

/**
 * 获取工单分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const orderPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
};

/**
 * 根据ID获取工单详情
 * @returns
 */
export const orderInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
};

/**
 * 获取工单列表
 * @returns
 */
export const orderListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
};

/**
 * 工单编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E7%AB%99%E7%82%B9/modifyUsingPOST}
 * @param {String} name 名称
 * @param {String} address 地址
 * @param {String} contect 联系人
 * @param {String} longitue 经度
 * @param {String} latitude 纬度
 * @param {String} orderCode 工单编码
 * @param {String} orderSubtype 工单主体类型
 * @param {String} orderType 工单类型
 * @param {String} tel 电话号码
 * @returns
 */
export const orderAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.add, data }).then((res) => {
          resolve(true);
        });
      },
      onCancel() {
        message.warning('已取消');
        resolve('');
      },
    });
  });
};

/**
 * 工单编辑 文档地址 {@link http://192.168.1.52:8080/api/doc.html#/default/%E7%AB%99%E7%82%B9/modifyUsingPOST}
 * @param {String} name 名称
 * @param {String} address 地址
 * @param {String} contect
 * @param {String} longitue 经度
 * @param {String} latitude 纬度
 * @param {String} orderCode 工单编码
 * @param {String} orderSubtype 工单主体类型
 * @param {String} orderType 工单类型
 * @param {String} tel 电话号码
 * @returns
 */
export const orderModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        });
      },
      onCancel() {
        message.warning('已取消');
        resolve('');
      },
    });
  });
};

/**
 * 删除工单接口
 * @param {*} id
 * @returns
 */
export const orderDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前工单数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }));
      },
      onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  });
};

/**
 * 更新plc图 {@link http://192.168.1.66:38080/api/doc.html#/default/%E7%AB%99%E7%82%B9/updateGraphUsingPOST}
 * @param {String} id
 * @param {String} graph PIC图
 * @returns
 */
export const updateGraphApi = (data) => {
  return new Promise(async (resolve, reject) => {
    await defHttp
      .post({ url: API.updateGraph, data })
      .then((res) => {
        message.success('保存成功');
        resolve(res);
      })
      .catch(() => {
        message.error('保存失败');
        reject();
      });
  });
};

export default {
  pageUrl: API.page,
};
